#include "Vector4.h"
#include "Vector3.h"
#include <cassert>

namespace DYMath
{
	Vector4::Vector4() : x(0), y(0), z(0), w(0) { }

	Vector4::Vector4(const Vector4& v) : x(v.z), y(v.y), z(v.z), w(v.w) { }

	Vector4::Vector4(float a, float b, float c, float d) : x(a), y(b), z(c), w(d) { }

	float& Vector4::operator[](int i)
	{
		assert(i >= 0 && i < 4);
		return (&x)[i];
	}

	const float& Vector4::operator[](int i) const
	{
		assert(i >= 0 && i < 4);
		return (&x)[i];
	}

	Vector4 Vector4::operator-()
	{
		return Vector4(-x, -y, -z, -w);
	}

	Vector4& Vector4::operator=(const Vector3& v)
	{
		x = v.x;
		y = v.y; 
		z = v.z;
		w = 1.0f;
		return *this;
	}

	Vector4 operator+(float scaler, const Vector4& v)
	{
		return Vector4(scaler + v.x, scaler + v.y, scaler + v.z, scaler + v.w);
	}

	Vector4 operator+(const Vector4& v, float scaler)
	{
		return Vector4(v.x + scaler, v.y + scaler, v.z + scaler, v.w + scaler);
	}

	Vector4 operator+(const Vector4& v1, const Vector4& v2)
	{
		return Vector4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
	}

	Vector4 operator-(float scaler, const Vector4& v)
	{
		return Vector4(scaler - v.x, scaler - v.y, scaler - v.z, scaler - v.w);
	}

	Vector4 operator-(const Vector4& v, float scaler)
	{
		return Vector4(v.x - scaler, v.y - scaler, v.z - scaler, v.w - scaler);
	}

	Vector4 operator-(const Vector4& v1, const Vector4& v2)
	{
		return Vector4(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
	}

	Vector4 operator*(float scaler, const Vector4& v)
	{
		return Vector4(scaler * v.x, scaler * v.y, scaler * v.z, scaler * v.w);
	}

	Vector4 operator*(const Vector4& v, float scaler)
	{
		return Vector4(v.x * scaler, v.y * scaler, v.z * scaler, v.w * scaler);
	}

	Vector4 operator*(const Vector4& v1, const Vector4& v2)
	{
		return Vector4(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w);
	}

	Vector4 operator/(float scaler, const Vector4& v)
	{
		return Vector4(scaler / v.x, scaler / v.y, scaler / v.z, scaler / v.w);
	}

	Vector4 operator/(const Vector4& v, float scaler)
	{
		return Vector4(v.x / scaler, v.y / scaler, v.z / scaler, v.w / scaler);
	}

	Vector4 operator/(const Vector4& v1, const Vector4& v2)
	{
		return Vector4(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w);
	}
}
